home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_MacPaint / Source / shared.subproj / RCS / ProgressIndicator.m,v < prev    next >
Text File  |  1995-06-12  |  6KB  |  209 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  beta10:1.2;
  5. locks    death:1.3;
  6. comment  @@;
  7.  
  8.  
  9. 1.3
  10. date     93.04.04.23.45.05;  author death;  state Exp;
  11. branches ;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     93.01.10.15.08.42;  author death;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     92.07.26.14.00.22;  author death;  state Exp;
  21. branches ;
  22. next     ;
  23.  
  24.  
  25. desc
  26. @Initial revision of this view
  27. @
  28.  
  29.  
  30. 1.3
  31. log
  32. @Sun Apr  4 23:45:04 PDT 1993
  33. @
  34. text
  35. @#import "ProgressIndicator.h"
  36. #import "ProgressInd.h"
  37. @@implementation ProgressIndicator
  38. // #import <dpsclient/psops.h>
  39. #import <dpsclient/wraps.h>    // for PSsetgray()
  40. #import <appkit/graphics.h>    // for NX_BLACK and _WHITE
  41.  
  42. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  43. //    Method:        drawSelf::
  44. //    Parameters:    the rectangles to draw in, and a count of how many there are.
  45. //    Returns:     self
  46. //    Stores:        n/a
  47. //    Description:
  48. //        This redraws the indicator object.  Because of the simplicity of the object,
  49. //        we ignore the rects and draw the whole thing every time.
  50. //    Bugs:
  51. //        I can't remember if I must manually flush the image if we're buffered or not...
  52. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  53.  
  54. - drawSelf:(const NXRect *)rects :(int)rectCount
  55. {
  56.     NXRect    theFrame;
  57.     NXRect *myFrame = &theFrame;
  58.     Real        height, width, radius, percent;
  59.     [self getBounds: myFrame];
  60.     //
  61.     //    Fill our rectangle with grey
  62.     //
  63.     PSsetgray(NX_LTGRAY);
  64.     NXRectFill(myFrame);
  65.     //
  66.     //    Now, if needed, draw the indicator.
  67.     //
  68.     if (active == YES)
  69.     {
  70.         percent =  CurrentValue / numUnits;
  71.         if (percent < 0 )    // One of the two has the wrong sign... negative progress, essentially
  72.             percent = 0;
  73.         if (percent > 1)
  74.             percent = 1;
  75.         //
  76.         //    Calculate smaller dimension use as a radius
  77.         //
  78.         height = NX_HEIGHT(myFrame);
  79.         width = NX_WIDTH(myFrame);
  80.         if (height > width)
  81.             radius = width / 2;
  82.         else
  83.             radius = height / 2;
  84.         DrawIndicator(360*percent, NX_MIDX(myFrame) ,NX_MIDY(myFrame), radius);
  85.     }
  86.     return self;
  87. }
  88.  
  89.  
  90.  
  91. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  92. //    Method:        init
  93. //    Parameters:    none
  94. //    Returns:     self
  95. //    Stores:        n/a
  96. //    Description:
  97. //        This merely initalizes the instance variables, as you would expect.
  98. //    Bugs:
  99. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  100. - init
  101. {
  102.     [super init];
  103.     
  104.     active = NO;
  105.     numUnits = 0;
  106.     CurrentValue = 0;
  107.     return self;
  108. }
  109.  
  110.  
  111. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  112. //    Method:        ActivateWithGoal
  113. //    Parameters:    A number that constitutes the 'finish line'.
  114. //    Returns:     self
  115. //    Stores:        n/a
  116. //    Description:
  117. //        This does several things.  First, it makes us active, which means we will
  118. //        now draw ourself.  Second, we set up the specified count as the number that
  119. //        constitutes our goal (That is, reaching count is 100% done).  We establish
  120. //        the current progression towards that goal as 0.  Note that the goal can be
  121. //        negative if desired.  Starting point is always 0 though.
  122. //    Bugs:
  123. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  124. - ActivateWithGoal: (Real) count
  125. {
  126.     active = YES;
  127.     numUnits = count;
  128.     CurrentValue = 0;
  129.     [window display];
  130.     return self;
  131. }
  132.  
  133.  
  134. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  135. //    Method:        Deactivate
  136. //    Parameters:    none
  137. //    Returns:     self
  138. //    Stores:        n/a
  139. //    Description:
  140. //        After clearing the internal counter and current value, and setting the active
  141. //        flag to false, this will cause this indicator to be cleared.
  142. //    Bugs:
  143. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  144. - Deactivate
  145. {
  146.     active = NO;
  147.     numUnits = 0;
  148.     CurrentValue = 0;
  149.     [window display];
  150.     return self;
  151. }
  152.  
  153.  
  154. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  155. //    Method:        IncrementBy:
  156. //    Parameters:    A value to increment our current value by
  157. //    Returns:     self
  158. //    Stores:        n/a
  159. //    Description:
  160. //        Unsurprisingly, we take our argument, and increment our current value
  161. //        by it, and then redraw.  This will cause the arc on the screen to fill a bit more
  162. //        of the circle.  (or if the units are the reverse sign of the gooal, cause it to back up)
  163. //    Bugs:
  164. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  165. - IncrementBy: (Real) units
  166. {
  167.     CurrentValue += units;
  168.     [window display];
  169.     return self;
  170. }
  171.  
  172.  
  173. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  174. //    Method:        SetTo:
  175. //    Parameters:    A new value to set the indicator to.
  176. //    Returns:     self
  177. //    Stores:        n/a
  178. //    Description:
  179. //        This discards whatever setting this object had before, and sets the current
  180. //        value to the specified setting.  The indicator is then redrawn to reflect this
  181. //        change.
  182. //    Bugs:
  183. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  184. - SetTo: (Real) units;
  185. {
  186.     CurrentValue = units;
  187.     [window display];
  188.     return self;
  189. }
  190.  
  191. @@end
  192. @
  193.  
  194.  
  195. 1.2
  196. log
  197. @Sun Jan 10 15:08:41 PST 1993
  198. @
  199. text
  200. @@
  201.  
  202.  
  203. 1.1
  204. log
  205. @Initial revision
  206. @
  207. text
  208. @@
  209.